package com.onetech.adrewards.free.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

import com.google.analytics.tracking.android.EasyTracker;
import com.google.analytics.tracking.android.Fields;
import com.google.analytics.tracking.android.MapBuilder;
import com.google.analytics.tracking.android.Tracker;
import com.onetech.adrewards.free.R;
import com.onetech.adrewards.free.customviews.LoadMoreListView;
import com.onetech.adrewards.free.customviews.LoadMoreListView.OnLoadMoreListener;
import com.todddavies.components.progressbar.ProgressWheel;

public class BaseAdsFragment extends Fragment implements OnClickListener, OnLoadMoreListener{
	protected View mView;
	protected View mNotFoundData=null;
	protected View mWaitingForLoading=null;
	protected View mBtnRetry=null;
	protected ProgressWheel mProgress=null;
	protected LoadMoreListView mListView;
	
	protected int pageNo=1;
	
	protected Tracker mTracker;
	protected int userCoins;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	protected void initNotFoundAndLoadingView(){
		mNotFoundData=(LinearLayout)mView.findViewById(R.id.notFoundDataContainer);		
		mWaitingForLoading=(LinearLayout)mView.findViewById(R.id.waitingLoading);
		mProgress=(ProgressWheel)mView.findViewById(R.id.progressWheel);
		mProgress.spin();
		showNotFoundOrLoadingView(false, true);
		mBtnRetry=(LinearLayout)mView.findViewById(R.id.btnRetry);
		mTracker = EasyTracker.getInstance(getActivity());
	}
	protected void initRetryButtonListener(){
		mBtnRetry.setOnClickListener(this);
	}
	protected void showNotFoundOrLoadingView(boolean isShowNotFound,boolean isShowLoading){
		if(isShowNotFound){
			mNotFoundData.setVisibility(View.VISIBLE);
		}else{
			mNotFoundData.setVisibility(View.GONE);
		}
		if(isShowLoading){
			mWaitingForLoading.setVisibility(View.VISIBLE);
			mProgress.spin();
		}else{
			mWaitingForLoading.setVisibility(View.GONE);
			mProgress.stopSpinning();
		}
	}
	@Override
	public void onClick(View v) {
		
	}
	@Override
	public void onLoadMore() {
		
	}
	protected void trackingView(String view) {
        try {
            mTracker.set(Fields.SCREEN_NAME, view);            
            mTracker.send(MapBuilder.createAppView().build());            
		} catch (Exception e) {
		}
	}
}
